package com.cpi.cornpp.sapfiles.converter;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

import com.cpi.cornpp.sapfiles.view.SAPFileView;
import com.cs.common.init.SystemParameterCollection;
import com.cs.common.init.beans.SAPFileBean;
import com.cs.common.init.beans.SystemParameterBean;

public class SAPFileConverter {
	/**
	 * 
	 * @param bean
	 * @return
	 */
	public SAPFileView convertBeanToView(SAPFileBean bean){
		SAPFileView view = null;
		SystemParameterBean parameter = null;		
		parameter = SystemParameterCollection.getInstance().getSystemParameterBean("PATH_SAP_FILES");
		view = new SAPFileView();
		view.setClassName(bean.getClassName());
		view.setLogicalFileName(bean.getLogicalFileName());
		view.setPhysicalFileName(bean.getPhysicalFileName());
		view.setFullFilePath(new StringBuffer(parameter.getValue()).append(bean.getPhysicalFileName()).toString());
		view.setOffSetLines(Integer.valueOf(bean.getOffSetLines()));
		view.setSystem(bean.getSystem());
		
		return view;
	}
	
	/**
	 * 
	 * @param list
	 * @return
	 */
	public ArrayList convertBeansToViews(Collection list){
		ArrayList views = new ArrayList(0);
		for (Iterator iterator = list.iterator(); iterator.hasNext();) {
			SAPFileBean bean = (SAPFileBean) iterator.next();
			views.add(convertBeanToView(bean));			
		}
		return views;
	}
	
	
}
